﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sniper_Scope : MonoBehaviour
{
    int[] scope = { 80, 20, 5 };
    //倍镜数组索引
    int i = 1;
    int index=0;
    private float lerp=0;
    void Start()
    {
        //初始镜头距离为80
        Camera.main.GetComponent<Camera>().fieldOfView = 80;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            lerp = Mathf.Lerp( Camera.main.GetComponent<Camera>().fieldOfView, scope[i], 0.05f)- Camera.main.GetComponent<Camera>().fieldOfView;
            index = i;
            i++;
            if (i==scope.Length)
            {
                i = 0;
            }
        }
        transform.GetComponent<Camera>().fieldOfView += lerp;
        if (transform.GetComponent<Camera>().fieldOfView==scope[index])
        {
            lerp = 0;
        }
        //获取鼠标滚轮增量
        float s = Input.GetAxis("Mouse ScrollWheel");//0.1
        //如果开镜到8倍镜可以在4到8倍调整
        if (i==0)
        {
            Camera.main.fieldOfView -= s*10 ;
            Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView,5f,20f);
            /*
            if (Camera.main.fieldOfView<=10)
            {
                Camera.main.fieldOfView = 10;
            }
            if (Camera.main.fieldOfView>=20)
            {
                Camera.main.fieldOfView = 20;
            }
            */
        }
    }
}
